package com.gisuni.sddc.platformManager.service;

import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.json.JSONArray;
import org.json.JSONObject;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import com.gisuni.sddc.platformManager.dao.LayerTableNameDao;
import com.gisuni.sddc.platformManager.dao.ProjectRTypeDetailDao;
import com.gisuni.sddc.platformManager.dao.ProjectTypeDao;
import com.gisuni.sddc.platformManager.model.ProjectRTimenode;
import com.gisuni.sddc.platformManager.model.ProjectTimenodeDetail;
import com.gisuni.sddc.platformManager.model.ProjectTypeTimenode;
import com.gisuni.sddc.platformManager.model.Response;
import com.gisuni.sddc.util.StringUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@IocBean
public class ProjectRTypeDetailService   {

	private Log log = Logs.getLog(ProjectRTypeDetailService.class);    
    @Inject
    private ProjectRTypeDetailDao projectRTypeDetailDao;
	@Inject
    private LayerTableNameDao layerTableNameDao; 
	@Inject
    private ProjectTypeDao projectTypeDao;
	
	/**
	 * 导出的Excel文件中 字段对应的位置:列数
	 */
	static Map baseMapExcelColumn = new HashMap();
	
	static{
		initMap();
	}
  
    public  JSONObject findEntityByIdAndType(String id,String type) {
    	Map<String, String> map  = layerTableNameDao.getTableName();
    	String tableName = map.get(type);
		StringBuffer sbfSQL =  new StringBuffer(" select t.pkuuid,t.xmmc, t3.id,t3.project_type_id,t3.project_type_name,t3.project_start_time,t3.project_plan_pay_money  from "+tableName+" t "
				+" left join (select t1.id, t1.project_id,t1.project_type_id,t1.project_start_time,t1.project_plan_pay_money,t2.project_type_name from sddcgisplatform.project_r_timenode t1 "  
				+" left join sddcgisplatform.project_type t2 on t1.project_type_id = t2.id) t3 on t.pkuuid = t3.project_id where t.pkuuid ='"+id+"'");
        System.out.println("type+id SQL:"+sbfSQL);
		return projectRTypeDetailDao.querySqlReturnJSONObj(sbfSQL.toString());
    }
 

	public Response updateEntity(HttpServletRequest request) throws Exception{
	     
		 Response res = new Response();
	   	 res.setSuccess(false);
	   	 String  id = request.getParameter("id");//主表ID
	   	 String  projectId = request.getParameter("projectId");//项目ID
	   	 String   projectName = request.getParameter("name");//项目名称
	   	 String  projectTypeId = request.getParameter("projectType");//项目类型ID
	   	 String  oldprojectTypeId = request.getParameter("oldProjectType");
	   	 
	     String  projectStartTime = request.getParameter("projectStartTime");
	     String  oldprojectStartTime = request.getParameter("oldProjectStartTime");
	   	
	   	 String  projectPlanPayMoney = request.getParameter("projectPlanPayMoney");
	     String  remark = request.getParameter("remark");
	     
	     if(!StringUtil.isNullOrEmpty(projectPlanPayMoney)){
	    	 try{
	    		 Double.parseDouble(projectPlanPayMoney);
	    	 }catch(Exception e){
	    		 res.setMsg("请输入数字");
	    		 return res;
	    	 }
	     }
	     
	     //项目初次配置项目类型
	     if(StringUtil.isNullOrEmpty(id)){
	    	 //新增
	    	 ProjectRTimenode entity = new ProjectRTimenode();
	    	 String orgId = UUID.randomUUID().toString().replaceAll("-", "");
	    	 entity.setId(orgId);
	    	 entity.setProjectId(projectId);
	    	 entity.setProjectTypeId(projectTypeId);
	    	 entity.setProjectPlanPayMoney(projectPlanPayMoney);
	    	 entity.setProjectStartTime(projectStartTime);
	    	 entity.setProjectName(projectName);
	    	 //保存主表信息
	    	 projectRTypeDetailDao.addProjectRTimenode(entity);
	    	 //保存从表信息
	    	 addProjectTimenodeDetail(orgId,projectId,projectTypeId,projectStartTime);
	     }else{
	    	 //更新主表信息
	    	 String updateSQL = "update SDDCGISPLATFORM.PROJECT_R_TIMENODE set PROJECT_TYPE_ID='"+projectTypeId+"',PROJECT_START_TIME='"+projectStartTime+"',PROJECT_PLAN_PAY_MONEY='"+projectPlanPayMoney+"' where ID = '"+id+"'";
	    	 projectRTypeDetailDao.executeSQL(updateSQL);
	    	 
	    	 //更新从表信息
	    	 
		     //若更改了项目类型:删除从表关联的信息,重新创建
		     if(!projectTypeId.equals(oldprojectTypeId)){
		    	 //删除从表信息
		    	 updateSQL = " delete from SDDCGISPLATFORM.project_timenode_detail where PROJECT_R_TIMENODE_ID = '"+id+"'";
		    	 projectRTypeDetailDao.executeSQL(updateSQL);
		    	 //创建从表信息
		    	 addProjectTimenodeDetail(id,projectId,projectTypeId,projectStartTime);
		    	 
		     }else{
		    	 //  若更改了项目启动时间 初始化后,从表中的日期不进行更改!!! 
		    	 
		     }
	     }

	     res.setSuccess(true);
		return res;
	}
	
 

	//根据项目类型/主表ID 创建具体项目的节点信息
	private void addProjectTimenodeDetail(String orgId,String projectId, String projectTypeId, String projectStartTime) throws ParseException {
		//查询项目类型的所有节点
		List<ProjectTypeTimenode> typeTimeNodeList = projectRTypeDetailDao.queryProjectTypeTimenodeByTypeId(projectTypeId);
		int day = 0;//日期周期
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date startDate = sdf.parse(projectStartTime);
		Calendar   calendar   =   new   GregorianCalendar(); 
		
		//
		for(ProjectTypeTimenode node : typeTimeNodeList){
			ProjectTimenodeDetail detail = new ProjectTimenodeDetail();
			day+=node.getTimenodeCycle();
			String id = UUID.randomUUID().toString().replaceAll("-", "");
			detail.setId(id);
			detail.setProjectId(projectId);
			detail.setTimenodeId(node.getId());
			detail.setProjectRTimenodeId(orgId);
			detail.setProjectId(projectId);
			
			//初始化项目节点时间
		    calendar.setTime(startDate); 
		    calendar.add(calendar.DATE,day); 
       	    detail.setPlanFinishTime(calendar.getTime());
		     
			projectRTypeDetailDao.addProjectTimenodeDetail(detail);
		}
		
	}


	//
	public Response queryBaseEntityAll(int from, int to, String projectName,String projectType) {
		Response response = new Response();
		response.setSuccess(false);
		String Result=null;
		
		if(StringUtil.isNullOrEmpty(projectType)){
			projectType="ZCQXM";
		}
		try {
	    	Map<String, String> map  = layerTableNameDao.getTableName();
	    	String tableName = map.get(projectType);
	    	
	    	//初始化pkuuid
	    	projectRTypeDetailDao.executeSQL("update  "+tableName+" t set t.pkuuid = sys_guid() where t.pkuuid is null");
	    	
			StringBuffer pageSbfSQL =  new StringBuffer(" select * from (");
			
			StringBuffer sbfSQL =  new StringBuffer(" select t.pkuuid  ,t.xmmc,t3.id"
					+ " ,t3.project_type_name,t3.project_start_time,t3.project_plan_pay_money,rownum rs from "+tableName+" t "
							+" left join (select t1.id,t1.project_id,t1.project_start_time,t1.project_plan_pay_money,t2.project_type_name from sddcgisplatform.project_r_timenode t1 "  
							+" left join sddcgisplatform.project_type t2 on t1.project_type_id = t2.id) t3 on t.pkuuid = t3.project_id where 1=1 ");
			
			if(!StringUtil.isNullOrEmpty(projectName)){
				sbfSQL.append(" and t.xmmc like '%"+projectName.trim()+"%' ");
			}
			
//			if(!StringUtil.isNullOrEmpty(projectType)){
//				sbfSQL.append(" and t3.project_type_name like '%"+projectType.trim()+"%' ");
//			}
			pageSbfSQL.append(sbfSQL.toString()+" and rownum<="+to+") where rs>"+from);
			
			//sbfSQL.append(" order by t3.project_type_name ");
			
			//分页数据
			System.out.println(pageSbfSQL);
			String pageResult = projectRTypeDetailDao.queryBaseEntityAll(  from,  to, pageSbfSQL.toString());
			//长度
			String allResult = projectRTypeDetailDao.queryBaseEntityAll(  from,  to, sbfSQL.toString());
			
			if(!StringUtil.isNullOrEmpty(pageResult)){
				response.setResult(pageResult);
				JSONArray total = new JSONArray(allResult);
				response.setTotal(total.length());
			}else{
				response.setResult("");
				response.setTotal(0);
			}
			response.setSuccess(true);
			return response;
		}catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
			response.setMsg("查询失败");
			return response;
		}
		
	}
	
	
	public String jsonToString(String json ,String name){
		
		JSONArray resultJsonArr = new JSONArray(json);
		StringBuffer sbf = new StringBuffer();
		if (resultJsonArr != null && resultJsonArr.length() > 0) {
			for (int i = 0; i < resultJsonArr.length(); i++) {
				JSONObject ret = (JSONObject) resultJsonArr.get(i);
				Iterator iterator = ret.keys();
				while (iterator.hasNext()) {
					String key = (String) iterator.next();
					 
					if(name.equals(key)){
						String value = (String) ret.get(key);
						sbf.append(value);
					}
				}	
			}
		}
		return sbf.toString();
		
	}

	/**
	 * 多条件查询
	 * 注:未配置项目类型的项目不会查到
	 * @param request
	 * @return
	 */
	public Response find(HttpServletRequest request) {
		Response response = new Response();
		response.setSuccess(false);
		String Result=null;
		try{
			
		   	String  region = request.getParameter("region");//项目所属区域
		   	String  projectName = request.getParameter("projectName");//项目名称
		   	String  projectType = request.getParameter("projectType");//项目类型ID
		   	String  projectTypeNodeId = request.getParameter("projectTypeNodeId");//完成的节点ID
		   	 
		    String  startTime = request.getParameter("startTime");//计划开始时间
		    String  endTime = request.getParameter("endTime");//计划结束时间
		   	 
		   	String  startArea  = request.getParameter("areafrom");//项目占地面积
		   	String  endArea  = request.getParameter("areato");//项目占地面积
		     
	    	Map<String, String> map  = layerTableNameDao.getTableName();
	    	String tableName = map.get("ZCQXM");
	    	
			StringBuffer sbfA = new  StringBuffer();
			//pkuuid(项目ID),项目名称,计划支出总金额,实际支出总金额
			sbfA.append(" select t.pkuuid ,t.xmmc,tDetail.planPay,tDetail.actPay from "+tableName+" t ");
			
			sbfA.append(" inner join  (");
					 
					StringBuffer sbfB = new  StringBuffer();
					sbfB.append(" select  t1.project_id,nvl(t1.project_plan_pay_money,0)planPay ,sum(nvl(t2.actual_pay_money,0)) actPay from sddcgisplatform.project_r_timenode t1 left join sddcgisplatform.project_timenode_detail t2 on t1.id=t2.project_r_timenode_id where 1=1");
					//项目类型
					if(!StringUtil.isNullOrEmpty(projectType) && !"All".equals(projectType)){
						sbfB.append(" and t1.project_type_id='"+projectType+"'");
					}
					 

					//项目类型节点
					if(!StringUtil.isNullOrEmpty(projectTypeNodeId)){
				    	//当选择整个项目已完成时
				    	String projectSQL = null;
				    	if("All".equals(projectTypeNodeId)){
				    		projectSQL = getFinishProject();
				    		if(!StringUtil.isNullOrEmpty(projectSQL)){
				    			sbfB.append(" and t1.project_id in ("+projectSQL+")");
				    		}
				    	}else{
				    		sbfB.append(" and (t2.timenode_id='"+projectTypeNodeId+"' and t2.status = '1')");
				    	}
					}
					//计划开始时间
					if(!StringUtil.isNullOrEmpty(startTime)  ){
						sbfB.append(" and t2.plan_finish_time >= to_date('"+startTime+"','yyyy-MM-dd')");
					}
					//计划结束时间
					if(!StringUtil.isNullOrEmpty(endTime)){
						sbfB.append(" and t2.plan_finish_time <= to_date('"+endTime+"','yyyy-MM-dd')");
					}
					sbfA.append(sbfB.toString());
					sbfA.append(" group by t1.project_id,t1.project_plan_pay_money ) tDetail on t.pkuuid = tDetail.project_id ");
			
			sbfA.append(" where 1=1 ");
			
			//项目所属区域(城市公司字段)
			if(!StringUtil.isNullOrEmpty(region) && !"所有公司".equals(region)){
				sbfA.append(" and t.csgs like '%"+region+"%'");
			}
			//项目名称
			if(!StringUtil.isNullOrEmpty(projectName)){
				sbfA.append(" and t.xmmc like '%"+projectName+"%'");
			}
			//面积
			if(!StringUtil.isNullOrEmpty(startArea)){
				sbfA.append(" and t.xmzdmj >="+startArea);
			}
			//面积
			if(!StringUtil.isNullOrEmpty(endArea)){
				sbfA.append(" and t.xmzdmj <="+endArea);
			}



			Result = projectRTypeDetailDao.querySql(sbfA.toString());
			response.setResult(Result);
			response.setSuccess(true);
		}catch(Exception e){
			log.error(e.getMessage());
			throw e;
		}
		return response;
	}
	

	/**
	 * 得到所有节点已完成的项目ID
	 * @return
	 */
	private String getFinishProject() {
    	
		//--所有完成
    	String allFinish = "select project_id,count(1) allrows,wm_concat(status) allStatus from sddcgisplatform.PROJECT_TIMENODE_DETAIL t group by t.project_id ";
    	try{
        	String data =  projectRTypeDetailDao.querySql(allFinish);
        	if(data!=null){
        		StringBuffer returnSQL = new StringBuffer("''");
        		JSONArray arr = new JSONArray(data);
        		for(int i=0;i<arr.length();i++){
        			JSONObject obj = (JSONObject) arr.get(i);
        			String id = (String) obj.get("PROJECT_ID");
        			int allrows = Integer.parseInt((String)obj.get("ALLROWS"));
        			if(obj.has("ALLSTATUS")){
            			String allStatus = (String) obj.get("ALLSTATUS");
            			if(!StringUtil.isNullOrEmpty(allStatus)){
            				int n =allStatus.split(",").length;
            				if(n==allrows){
            					String temp = "";
            					for(int c=0;c<n;c++){
            						temp+="1";
            					}
            					if(temp.equals(allStatus.replaceAll(",", ""))){
            						returnSQL.append(","+id);
            					}
            				}
            						
            			}
        			}

        		}
        		return returnSQL.toString();
        	}
    	}catch(Exception e){
			log.error(e.getMessage());
			throw e;
    	}
    	
		return null;
	}
	
	
	/**
	 * 多条件查询[改方法未使用]
	 * ,无计划/实际总金额
	 * 注:未配置项目类型的项目不会查到
	 * @param request
	 * @return
	 */
	public Response find2(HttpServletRequest request) {
		Response response = new Response();
		response.setSuccess(false);
		String Result=null;
		try{
			
		   	String  region = request.getParameter("region");//项目所属区域
		   	String  projectName = request.getParameter("projectName");//项目名称
		   	String  projectType = request.getParameter("projectType");//项目类型ID
		   	String  projectTypeNodeId = request.getParameter("projectTypeNodeId");//完成的节点ID
		   	 
		    String  startTime = request.getParameter("startTime");//计划开始时间
		    String  endTime = request.getParameter("endTime");//计划结束时间
		   	 
		   	String  startArea  = request.getParameter("areafrom");//项目占地面积
		   	String  endArea  = request.getParameter("areato");//项目占地面积
		     
	    	Map<String, String> map  = layerTableNameDao.getTableName();
	    	String tableName = map.get("ZCQXM");
	    	 
			StringBuffer sbfA = new  StringBuffer();
			sbfA.append(" select t.pkuuid ,t.xmmc,nvl(project_plan_pay_money,0),tPay.actPay from "+tableName+" t ");
			 
			//关联支出总金额(在这个位置写其实有些不妥.先执行where条件为最佳写法)
//			sbfA.append(" left join ( select t.project_id,sum(nvl(t.actual_pay_money,0))  actPay from project_timenode_detail t group by t.project_id) tPay on t.pkuuid = tPay.project_id ");
			
			sbfA.append(" where 1=1 ");
			
			//项目所属区域(城市公司字段)
			if(!StringUtil.isNullOrEmpty(region) && !"所有公司".equals(region)){
				sbfA.append(" and t.csgs like '%"+region+"%'");
			}
			//项目名称
			if(!StringUtil.isNullOrEmpty(projectName)){
				sbfA.append(" and t.xmmc like '%"+projectName+"%'");
			}
			//面积
			if(!StringUtil.isNullOrEmpty(startArea)){
				sbfA.append(" and t.xmzdmj >="+startArea);
			}
			//面积
			if(!StringUtil.isNullOrEmpty(endArea)){
				sbfA.append(" and t.xmzdmj <="+endArea);
			}
			sbfA.append(" and t.pkuuid in (");
			 
			StringBuffer sbfB = new  StringBuffer();
			sbfB.append(" select t1.project_id from sddcgisplatform.project_r_timenode t1 left join sddcgisplatform.project_timenode_detail t2 on t1.id=t2.project_r_timenode_id where 1=1");
			//项目类型
			if(!StringUtil.isNullOrEmpty(projectType) && !"All".equals(projectType)){
				sbfB.append(" and t1.project_type_id='"+projectType+"'");
			}
			

			//项目类型节点
			if(!StringUtil.isNullOrEmpty(projectTypeNodeId)){
		    	//当选择整个项目已完成时
		    	String projectSQL = null;
		    	if("All".equals(projectTypeNodeId)){
		    		projectSQL = getFinishProject();
		    		if(!StringUtil.isNullOrEmpty(projectSQL)){
		    			sbfB.append(" and t1.project_id in ("+projectSQL+")");
		    		}
		    		
		    	}else{
		    		sbfB.append(" and (t2.timenode_id='"+projectTypeNodeId+"' and t2.status = '1')");
		    	}
			}
			//计划开始时间
			if(!StringUtil.isNullOrEmpty(startTime)  ){
				sbfB.append(" and t2.plan_finish_time >= to_date('"+startTime+"','yyyy-MM-dd')");
			}
			//计划结束时间
			if(!StringUtil.isNullOrEmpty(endTime)){
				sbfB.append(" and t2.plan_finish_time <= to_date('"+endTime+"','yyyy-MM-dd')");
			}
			sbfA.append(sbfB.toString());
			sbfA.append(" )");
			
			Result = projectRTypeDetailDao.querySql(sbfA.toString());
			response.setResult(Result);
			response.setSuccess(true);
		}catch(Exception e){
			log.error(e.getMessage());
			throw e;
		}
		return response;
	}





	public String getTimeNodeByTypeId(String pkuuid) {
		String sql="select t.id as nodeid,"+ 
	   "t.notificationcycle  as notificationcycle,"+
	   "t.project_id  as projectId,"+
       "t.follow_user              as followUser,"+
       "t.plan_finish_time         as pftime,"+
       "t.actual_finish_time       as aftime,"+
       "t.actual_pay_money         as apmoney,"+
       "t.status                   as status,"+
       "prt.project_start_time     as pstime,"+
       "prt.project_plan_pay_money as pppmoney,"+
       "ptt.timenode_name          as nodename,"+
       "ptt.timenode_cycle         as nodecycle,"+
       "ptt.timenode_index         as nodeindex,"+
       "t.remark as remark"+
       " from project_timenode_detail t"+
       " left join project_r_timenode prt on prt.id = t.project_r_timenode_id "+
       " left join project_type_timenode ptt on ptt.id = t.timenode_id "+
       " where t.project_id in("+pkuuid+") order by t.project_id,nodeindex asc";
//		System.out.println(sql);
		return projectRTypeDetailDao.querySql(sql);
	}

	@SuppressWarnings("finally")
	public boolean update(HttpServletRequest request) throws  Exception {		
		String nodeId=request.getParameter("thisNodeId");
		ProjectTimenodeDetail detail=projectRTypeDetailDao.getProTimeNodeDetialById(nodeId);
//		System.out.println(detail);
		String planFTime=request.getParameter("thisPlanFTime");
		String acFTime=request.getParameter("ThisAFTime");
		String followUser=request.getParameter("thisFollowUser");
		String status=request.getParameter("thisIsFinished");
		String nodeACPy=request.getParameter("thisNodeAcPay");
		String notificationCycle=request.getParameter("NotificationCycle");
		int intNotificationCycle = 7; 
		if(!StringUtil.isNullOrEmpty(notificationCycle)){
			intNotificationCycle = Integer.parseInt(notificationCycle);
		}
		String BZ=request.getParameter("thisNodeBZ");
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		if(!StringUtil.isNullOrEmpty(planFTime)){
			Date datePFTime=sdf.parse(planFTime);
			detail.setPlanFinishTime(datePFTime);
		}
		if(!StringUtil.isNullOrEmpty(acFTime)){
			Date dateACFTime=sdf.parse(acFTime);
			detail.setActualFinishTime(dateACFTime);
		}else{
			detail.setActualFinishTime(null);
		}
		detail.setFollowUser(followUser);
		detail.setStatus(status);
		detail.setNotificationCycle(intNotificationCycle);
		detail.setActualPayMoney(nodeACPy);
        detail.setRemark(BZ);
        int flag= projectRTypeDetailDao.updateprojectRTypeDetail(detail);
        if(flag==1){
     	   return true;
        }
	 	return false;
	}
	
	
	/**
	 *  通过项目Id集查询数据导出Excel
	 * @param projectId
	 * @param response
	 * @throws Exception 
	 */
	public void exportZCQXMExcel(String projectIds, HttpServletResponse response) throws Exception {

		  if(StringUtil.isNullOrEmpty(projectIds)){
			return;
		  }
		
		  //测试
//		  projectIds = "10,28,29,57,29";
//		  String[] idsArr = projectIds.split(",");
		   
		  String[] idsArr = projectIds.split(",");
		  projectIds="";
		  for(String id :idsArr){
			  projectIds+=("'"+id+"',");
		  }
		  projectIds=projectIds.substring(0, projectIds.length()-1);
		
		/**
		 * 
		 * ZCQXM_1表字段
		PKUUID , OBJECTID , 项目名 , CODE , FQMC , CSMC , BZSJ , CSGS , HZLX , XH , XMMC , XMLX , XMDZ , TDQSF , WSGQBL , XMZDMJ , 
		SFYSG , SGWYMJ , SGWYMQXZQK , SFYSD , XCSFYGLRYJ , SYQYQX , XMDKQYQX , BZ , BZ2 , SHAPE
		ZCQXM_DETAIL表字段
		ID , ZYDMJ , JYDMJ , RJL , ZJRJM , WSJRJM , TDHQSJLMDJ , TDHQSJJG , YJSJ , YGHJ , ZJZJE , ZJNZJCB ,
		 ZJYF , ZJWF , ZJBZ , WLBNNZF , SFMZSDTJ , NZJCB , NJYSR , PKUUID
=======
		public String getTimeNodeByTypeId(String pkuuid) {
			System.out.println(pkuuid.toString());
			String sql="select t.id as nodeid,"+ 
		   "t.project_id  as projectId,"+
	       "t.follow_user              as followUser,"+
	       "t.plan_finish_time         as pftime,"+
	       "t.actual_finish_time       as aftime,"+
	       "t.actual_pay_money         as apmoney,"+
	       "t.status                   as status,"+
	       "prt.project_start_time     as pstime,"+
	       "prt.project_plan_pay_money as pppmoney,"+
	       "ptt.timenode_name          as nodename,"+
	       "ptt.timenode_cycle         as nodecycle,"+
	       "ptt.timenode_index         as nodeindex,"+
	       "t.remark as remark"+
	       " from project_timenode_detail t"+
	       " left join project_r_timenode prt on prt.id = t.project_r_timenode_id "+
	       " left join project_type_timenode ptt on ptt.id = t.timenode_id "+
	       " where t.project_id in("+pkuuid+")order by t.project_id,nodeindex asc";
			System.out.println(sql);
			return projectRTypeDetailDao.querySql(sql);
		}
		  
		 */
		
    	Map<String, String> map  = layerTableNameDao.getTableName();
    	String tableName = map.get("ZCQXM");
    	
		//基础的项目数据
		StringBuffer projectBaseDataSQL = new StringBuffer(" SELECT T.*,T1.ZYDMJ,T1.JYDMJ,T1.RJL,T1.ZJRJM,T1.WSJRJM,T1.TDHQSJLMDJ,T1.TDHQSJJG,T1.YJSJ,");
		projectBaseDataSQL.append(" T1.YGHJ,T1.ZJZJE,T1.ZJNZJCB,T1.ZJYF,T1.ZJWF,T1.ZJBZ,T1.WLBNNZF,T1.SFMZSDTJ,T1.NZJCB,T1.NJYSR ");
	    projectBaseDataSQL.append( " FROM "+tableName+" T LEFT JOIN SDDCGISPLATFORM.ZCQXM_DETAIL T1 ON T.PKUUID = T1.PKUUID where T.Pkuuid in ("+projectIds+")  order by t.csmc,t.csgs ");  
		JSONArray  baseDataArr = projectRTypeDetailDao.querySqlReturnJSONArray(projectBaseDataSQL.toString());
		
		
		//其他数据
		StringBuffer projectDetailSQL = new StringBuffer();
		StringBuffer templateSQL = new StringBuffer();
			templateSQL.append("select * from ( ");
			templateSQL.append("select t.project_id  , ");
			templateSQL.append("t.follow_user , ");
			templateSQL.append("t.plan_finish_time , ");
			templateSQL.append("t.actual_finish_time , ");
			templateSQL.append("t.actual_pay_money , ");
			templateSQL.append("t.status , ");
			templateSQL.append("prt.project_start_time , ");
			templateSQL.append(" prt.project_plan_pay_money , ");
			templateSQL.append(" ptt.timenode_name, ");
			templateSQL.append(" ptt.timenode_cycle, ");
			templateSQL.append(" ptt.timenode_index, ptt.project_type_name ");
			templateSQL.append(" from project_timenode_detail t ");
			templateSQL.append(" left join project_r_timenode prt on prt.id = t.project_r_timenode_id ");
			templateSQL.append(" left join  (select r.*,p.project_type_name from project_type_timenode r left join project_type p on r.project_type_id = p.id)  ptt on ptt.id = t.timenode_id ");
			templateSQL.append(" where t.project_id = 'idFlag' ");
			templateSQL.append(" order by ptt.timenode_index asc)");
			
			projectDetailSQL.append(templateSQL.toString().replaceAll("idFlag", idsArr[0]));
			if(idsArr.length>1){
				for(int i = 1;i<idsArr.length;i++){
					projectDetailSQL.append(" union all ");
					projectDetailSQL.append(templateSQL.toString().replaceAll("idFlag", idsArr[i]));
					
				}
			}
		
		JSONArray  otherDataArr = projectRTypeDetailDao.querySqlReturnJSONArray(projectDetailSQL.toString());
//		System.out.println("SQL:"+projectDetailSQL.toString());

		String sourceFile = "D:\\templateFile\\zcqxmTemplateFile\\zcqxm.xlsx";
		String destFile = "D:\\templateFile\\tempFile\\"+System.currentTimeMillis()+".xlsx";		
		
		executeExcel(baseDataArr, otherDataArr, sourceFile, destFile);
		
		FileInputStream fis = new FileInputStream(destFile);
		XSSFWorkbook workbook = new XSSFWorkbook(fis);
		
        if(workbook !=null){  
            try  
            {  
            	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            	
                String fileName = "中长期项目推进管控表" + sdf.format(new Date()) + ".xlsx";  
                fileName=new String(fileName.getBytes("gb2312"),"iso8859-1");
                String headStr = "attachment; filename=\"" + fileName + "\"";  
                response.setContentType("APPLICATION/OCTET-STREAM");  
                response.setHeader("Content-Disposition", headStr);  
                OutputStream out = response.getOutputStream();  
                workbook.write(out); 
                out.close();
                out.flush();
            }  
            catch (IOException e)  
            {  
                e.printStackTrace();  
            }  
        }
	}
	
		/**
		 * 
		 * @param arr 基础数据
		 * @param detailarr 补充数据
		 * @param sourceFile 模板文件路径
		 * @param destFile 生成文件路径
		 * @throws Exception
		 */
		private void executeExcel(JSONArray arr,JSONArray detailarr,String sourceFile,String destFile  ) throws Exception{
			
		
			//对补充数据进行处理
			Map<String,List<JSONObject>> detailMap = initDetailData(detailarr);
			
//			System.out.println(arr.toString());
//			System.out.println(detailarr.toString());
		
			//1.分城市
			//2.map list集合
			//3.迭代map 迭代list
			
			Set<String> set = new HashSet<String>();
			Map<String,List<JSONObject>> baseMap = new HashMap<String,List<JSONObject>>();
			for(int i=0;i<arr.length();i++){
				JSONObject obj = (JSONObject)arr.get(i);
				
//				Iterator iterator = obj.keys();
				String csmc = "其它";
				
//				while (iterator.hasNext()) {
					if(obj.has("CSMC") ){
						csmc = (String)obj.getString("CSMC");
						set.add(csmc);
						//TODO
//						break;
					}
//				}
				
				if(baseMap.get(csmc)== null ){
					baseMap.put(csmc, new ArrayList<JSONObject>());
					baseMap.get(csmc).add(obj);
				}else{
					baseMap.get(csmc).add(obj);
				}
			}
			
			File dir = new File("");
			String path  = dir.getAbsolutePath();
			initExcelFile(sourceFile,destFile,baseMap,detailMap);
			
		}
	
	
	    private void writeData(String file, Map<String, List<JSONObject>> baseMap,  Map<String, List<JSONObject>> detailMap) throws IOException {
	    	
	    	FileInputStream fis = new FileInputStream(file);
	    	
	    	// 去读取Excel
	    	XSSFWorkbook wb = new XSSFWorkbook(fis);
					
			Set<String> citySet  = baseMap.keySet();
			Iterator iterator = citySet.iterator();
			int i = 0;
			while(iterator.hasNext()){
				
				Sheet sheet1 = wb.getSheetAt(i);
				CellStyle style = initExcelCellStyle(wb);
				
				// 写入
				Row rowFrom = null;
				Cell cellFrom = null;
				
				String key = (String)iterator.next(); //sheet名
				wb.setSheetName(i, key);
				i++;
				List<JSONObject> listJSONOBJ = baseMap.get(key);
			
				//基础信息的记录数
				for (int j = 0; j < listJSONOBJ.size(); j++) { //设置为记录数
					rowFrom = sheet1.createRow(j*2+5);
					JSONObject jsObj = listJSONOBJ.get(j);
					jsObj.put("XH", (j+1)+"");
					
					rowFrom.setHeight((short)900);
					
					for (int k = 0; k <35; k++) {
						cellFrom = rowFrom.createCell(k);//创建每一个表格
						cellFrom.setCellStyle(style);
						String columnName = (String) baseMapExcelColumn.get(k);
						if(jsObj.has(columnName)){
							cellFrom.setCellValue((String)jsObj.get(columnName));
						}else{
							cellFrom.setCellValue("");
						}
					}
					
					//一些字段的特殊处理
					//TODO 需处理 pkuuid 空的问题 ???
					if(detailMap.get(jsObj.get("PKUUID"))!=null){
						List<JSONObject>  detailList = detailMap.get(jsObj.get("PKUUID"));
						
						//项目类型字段
						String typeKey = (String) baseMapExcelColumn.get(0);
						if( detailList.get(0).has(typeKey)){
							Object temp  = detailList.get(0).get(typeKey);
							if(temp!=null){
								rowFrom.getCell(0).setCellValue((String)temp);
							}
						}
	
						
						//计划总金额
						String playMoneyKey = (String) baseMapExcelColumn.get(17);
						Object playMoneyObj = null;
						if( detailList.get(0).has(playMoneyKey)){
							playMoneyObj  = detailList.get(0).get(playMoneyKey);
							if(playMoneyObj!=null){
								rowFrom.getCell(17).setCellValue((String)playMoneyObj);
							}
						}
						
						double actualPay=0;
						
						for (int k = 0; k < detailList.size(); k++) { //节点集合进行遍历
							JSONObject tempObj = detailList.get(k);
							
							//计划开始时间 - 结束时间
							String date ="";
	//						Object startTimeObj = tempObj.has("PROJECT_START_TIME")? tempObj.get("PROJECT_START_TIME") : null;
	//						
	//						Object endTimeObj   =  tempObj.has("PLAN_FINISH_TIME")? tempObj.get("PLAN_FINISH_TIME") : null;  
							
	//						if(startTimeObj!=null){
	//							date+=(String)startTimeObj;
	//						}
	//						
	//						if(endTimeObj!=null){
	//							date+=(" ~ "+(String)endTimeObj);
	//						}
							 //节点名称
							Object nodeNameObj  = tempObj.has("TIMENODE_NAME") ? tempObj.get("TIMENODE_NAME") : null;
							
							//实际完成时间
							Object actFinishTimeObj   =  tempObj.has("ACTUAL_FINISH_TIME")? tempObj.get("ACTUAL_FINISH_TIME") : null;   
							if(actFinishTimeObj!=null){
							  date+= (String)actFinishTimeObj ;
							  date = date.substring(0,10);
							}
							
							//该节点实际支付金额 actual_pay_money
							Object actPayMonObj   =  tempObj.has("ACTUAL_PAY_MONEY")? tempObj.get("ACTUAL_PAY_MONEY") : null;   
							if(actPayMonObj!=null){
								actualPay+= Double.parseDouble((String)actPayMonObj) ;
							}
							
							
							//节点
							if(nodeNameObj!=null ){
								if(k==0){
									//创建上一行
									Row tempRow = sheet1.createRow(j*2+4);
									for (int h = 0; h <35+detailList.size() ; h++) {
										Cell tempCell = tempRow.createCell(h);//创建每一个表格
										tempCell.setCellStyle(style);
									}
									
									//创建当前行节点Cell
									for (int b = 35; b <35+detailList.size(); b++) {
										cellFrom = rowFrom.createCell(b);//创建每一个表格
										cellFrom.setCellStyle(style);
										cellFrom.setCellValue("");
									}
								}

								Object TIMENODE_INDEX   =  tempObj.has("TIMENODE_INDEX")? tempObj.get("TIMENODE_INDEX") : null;  
//								if(TIMENODE_INDEX!=null){
//									System.out.println(((String)nodeNameObj).replace("\n", "")+" "+(String)TIMENODE_INDEX);
//								}
								
								sheet1.getRow(j*2+4).getCell(35+k).setCellValue((String)nodeNameObj);;
								
							}
							
							if(!date.equals("")){
								rowFrom.getCell(35+k).setCellValue(date);;
							}
						}
//						System.out.println("========");
						
						//总支付金额
						if(actualPay!=0){
							rowFrom.getCell(18).setCellValue(actualPay);
						}
						
						//总未支付金额
						if(playMoneyObj!=null){
							rowFrom.getCell(19).setCellValue(Double.parseDouble((String)playMoneyObj)-actualPay);
						}
						
					}
					
				}
				
				//
//				sheet1.getRow(4).getCell(0).setCellValue("");//定位焦点????
			}
			
			FileOutputStream fileOut = new FileOutputStream(file);
			wb.write(fileOut); 
			
	        if(fis!=null){
	        	fis.close();
	        }
			
	        if(fileOut!=null){
	        	fileOut.close();
	        }
		
	}
	
	    /**
	     * Excel表格样式
	     * @param wb
	     * @return
	     */
	    static CellStyle initExcelCellStyle(XSSFWorkbook wb){
			CellStyle style = wb.createCellStyle();
	//    	CellStyle style = new XSSFCellStyle();
			XSSFFont font = wb.createFont();
			font.setFontHeight(80);
			
		    style.setTopBorderColor(HSSFColor.BLACK.index);
	
	        style.setBottomBorderColor(HSSFColor.BLACK.index);
	
	        style.setLeftBorderColor(HSSFColor.BLUE.index);
	
	        style.setRightBorderColor(HSSFColor.BLACK.index);
	        
	
	        style.setBorderTop(HSSFCellStyle.BORDER_THIN);
	        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
	        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
	        style.setBorderRight(HSSFCellStyle.BORDER_THIN);
	         
	        font.setFontName("华文幼体");
	
	        font.setFontHeightInPoints((short)15);
	        
	
	        font.setColor(HSSFColor.BLACK.index);
	
	        font.setBoldweight(font.BOLDWEIGHT_BOLD);
	        
	        style.setFont(font);
	        
	        style.setFillBackgroundColor(HSSFColor.BLUE.index);
	        
	        return style;
	    }

    
	
		/**
		 * 将补充数据进行分类
		 * @param detailData
		 * @return
		 */
		 static Map<String,List<JSONObject>> initDetailData(JSONArray detailData) {
				Set<String> set = new HashSet<String>();
				Map<String,List<JSONObject>> map = new HashMap<String,List<JSONObject>>();
				for(int i=0;i<detailData.length();i++){
					JSONObject obj = (JSONObject)detailData.get(i);
					
					Iterator iterator = obj.keys();
					String csmc = "";
					
					while (iterator.hasNext()) {
						if(obj.get("PROJECT_ID")!=null){
							csmc = (String)obj.getString("PROJECT_ID");
							set.add(csmc);
							break;
						}
					}
					
					if(map.get(csmc)== null ){
						map.put(csmc, new ArrayList<JSONObject>());
						map.get(csmc).add(obj);
//						System.out.println(csmc+" : "+obj.toString());
					}else{
						map.get(csmc).add(obj);
//						System.out.println(csmc+" : "+obj.toString());
					}
				}
				
				return map;
			
		 }
	 
		/**
		 * 同一个Excel复制Sheet
		 * @param file
		 * @throws Exception
		 */
		 private void copyFromSheet(String file ) throws Exception  {
			Workbook wb = null;
			if (file.endsWith(".xlsx")) {//EXCEL2007
				wb = new XSSFWorkbook(new FileInputStream(new File(file)));
			}else if(file.endsWith(".xls")){//EXCEL97-2003
				wb = new HSSFWorkbook(new FileInputStream(new File(file)));
			}else{
				throw new Exception("");
			}
			
			Sheet sheet1 = wb.cloneSheet(0);
//			 workbook.setSheetName(sheet的索引, "名字");
			FileOutputStream fileOut = new FileOutputStream(file);
			wb.write(fileOut); 
	        fileOut.close(); 
	        
	        System.out.println(file + " 复制sheet成功!");
		}
    
		 
		/**
		 * 
		 * @param string 模板文件
		 * @param string2 复制的路径
		 * @param baseMap 写入的数据
		 * @throws Exception 
		 */
		private void initExcelFile(String source, String dest, Map<String, List<JSONObject>> baseMap , Map<String, List<JSONObject>> detailMap) throws Exception {
			
			copyAndWrite(source, dest);
			//默认已经有一个表了
			for(int i =0 ;i<baseMap.size()-1;i++){
				copyFromSheet(dest);
			}
			
			writeData(dest,baseMap,detailMap);
			
		}
	
	
	
	/**
	 * 复制文件AtoB
	 * @param source
	 * @param dest
	 * @throws Exception
	 */
	private void copyAndWrite(String source,String dest) throws Exception{
		// 复制文件  
        int byteread = 0; // 读取的字节数  
        InputStream in = null;  
        OutputStream out = null;  
  
            in = new FileInputStream(source);  
            File f = new File(dest);
            if(f.exists()){
            	f.delete();
            }
            out = new FileOutputStream(dest);  
            byte[] buffer = new byte[1024];  
  
            while ((byteread = in.read(buffer)) != -1) {  
                out.write(buffer, 0, byteread);  
            }  
           
            if(out!=null){
            	out.close();
            }
            if(in!=null){
            	in.close();
            }
            
	}
	
	
	
	static void initMap(){
		
		baseMapExcelColumn.put(0,"PROJECT_TYPE_NAME"); // 项目类型_
		baseMapExcelColumn.put(1,"XH"); // 序号
		baseMapExcelColumn.put(2,"CSGS"); // 区域 即所属城市公司
		baseMapExcelColumn.put(3,"XMMC"); // 项目名称
		baseMapExcelColumn.put(4,"YJZHSJ"); // 预计转化时间
		baseMapExcelColumn.put(5,"XMDZ"); // 项目地址
		baseMapExcelColumn.put(6,"TDQSF"); //土地权属方
		
		baseMapExcelColumn.put(7,"WSGQBL"); //我司股权比例
		baseMapExcelColumn.put(8,"ZYDMJ"); //总用地面积(万元)
		baseMapExcelColumn.put(9,"JYDMJ"); //我司净用地面积(万元)
		baseMapExcelColumn.put(10,"RJL"); //容积率  
		baseMapExcelColumn.put(11,"ZJRJM"); //总计容建面(万元)(含村的复建或其他)
		baseMapExcelColumn.put(12,"WSJRJM"); //我司计容建面(万元)
		baseMapExcelColumn.put(13,"TDHQSJLMDJ"); //土地获取实际楼面地价(万元)
		baseMapExcelColumn.put(14,"TDHQSJJG"); //土地获取实际价格(万元)
		baseMapExcelColumn.put(15,"YJSJ"); //预计售价(万元)
		baseMapExcelColumn.put(16,"YGHJ"); //预估货值(万元)
		
		baseMapExcelColumn.put(17,"PROJECT_PLAN_PAY_MONEY"); //(一次性支付/计划总金额)总金额 _
		baseMapExcelColumn.put(18,"YF"); //(一次性支付)已付 _ !!
		baseMapExcelColumn.put(19,"WF"); //(一次性支付)未付_
		
		baseMapExcelColumn.put(20,"ZJZJE"); //(租金)总金额
		baseMapExcelColumn.put(21,"ZJNZJCB"); //(租金)年租金成本
		baseMapExcelColumn.put(22,"ZJYF"); //(租金)已付
		baseMapExcelColumn.put(23,"ZJWF"); //(租金)未付
		baseMapExcelColumn.put(24,"ZJBZ"); //(租金)备注  
		baseMapExcelColumn.put(25,"WLBNNZF"); //未来半年拟支付(万元)
		baseMapExcelColumn.put(26,"SGWYMJ"); //上盖物业面积(万平米)
		baseMapExcelColumn.put(27,"SGWYMQXZQK"); //上盖物业目前现状情况描述
		baseMapExcelColumn.put(28,"SFMZSDTJ"); //是否满足收地条件
		baseMapExcelColumn.put(29,"SFYSD"); //是否已收地
		baseMapExcelColumn.put(30,"XCSFYGLRYJ"); //现场是否有管理人员及人数
		baseMapExcelColumn.put(31,"SYQYQX"); //剩余权益期限(年)
		baseMapExcelColumn.put(32,"XMDKQYQX"); //项目地块权益期限(承租/收购)
		baseMapExcelColumn.put(33,"NZJCB"); //年租金成本(万元)
		baseMapExcelColumn.put(34,"NJYSR"); //年经营收入(万元)
//		baseMapExcelColumn.put(25,"PKUUID"); //主表pkuuid		

		
		
		//select 'baseMapExcelColumn.put("'||t.column_name||'",1); //'||t.comments from user_col_comments t where t.TABLE_NAME='CYXZ_DETAIL';
//		baseMapExcelColumn.put("SGWYMJ",1); //上盖物业面积(万平米)
//		baseMapExcelColumn.put("SGWYMQXZQK",1); //上盖物业目前现状情况描述
//		baseMapExcelColumn.put("SFYSD",1); //是否已收地
//		baseMapExcelColumn.put("XCSFYGLRYJ",1); //现场是否有管理人员及人数
//		baseMapExcelColumn.put("SYQYQX",1); //剩余权益期限(年)
//		baseMapExcelColumn.put("XMDKQYQX",1); //项目地块权益期限(承租/收购)
//		baseMapExcelColumn.put("ID",1); //
//		baseMapExcelColumn.put("ZYDMJ",1); //总用地面积(万元)
//		baseMapExcelColumn.put("JYDMJ",1); //我司净用地面积(万元)
//		baseMapExcelColumn.put("RJL",1); //容积率  
//		baseMapExcelColumn.put("ZJRJM",1); //总计容建面(万元)(含村的复建或其他)
//		baseMapExcelColumn.put("WSJRJM",1); //我司计容建面(万元)
//		baseMapExcelColumn.put("TDHQSJLMDJ",1); //土地获取实际楼面地价(万元)
//		baseMapExcelColumn.put("TDHQSJJG",1); //土地获取实际价格(万元)
//		baseMapExcelColumn.put("YJSJ",1); //预计售价(万元)
//		baseMapExcelColumn.put("YGHJ",1); //预估货值(万元)
//		baseMapExcelColumn.put("ZJZJE",1); //(租金)总金额
//		baseMapExcelColumn.put("ZJNZJCB",1); //(租金)年租金成本
//		baseMapExcelColumn.put("ZJYF",1); //(租金)已付
//		baseMapExcelColumn.put("ZJWF",1); //(租金)未付
//		baseMapExcelColumn.put("ZJBZ",1); //(租金)备注  
//		baseMapExcelColumn.put("WLBNNZF",1); //未来半年拟支付(万元)
//		baseMapExcelColumn.put("SFMZSDTJ",1); //是否满足收地条件
//		baseMapExcelColumn.put("NZJCB",1); //年租金成本(万元)
//		baseMapExcelColumn.put("NJYSR",1); //年经营收入(万元)
//		baseMapExcelColumn.put("PKUUID",1); //主表pkuuid
//		baseMapExcelColumn.put("TDQSF",1); //土地权属方
//		baseMapExcelColumn.put("WSGQBL",1); //我司股权比例
//		baseMapExcelColumn.put("XMZDMJ",1); //项目占地面积(平方)
//		baseMapExcelColumn.put("SFYSG",1); //是否有上盖
		
//		detailMapExcelColumn
	}


	public String WYTZRelevanceTypeGetNode(String pId, String pName) {
		String typeId=projectTypeDao.getWYTZType().getId();
		ProjectRTimenode projectRTimenode=new ProjectRTimenode();
		projectRTimenode.setId(UUID.randomUUID().toString().replaceAll("-", ""));
		projectRTimenode.setProjectId(pId);
		projectRTimenode.setProjectName(pName);
		projectRTimenode.setProjectTypeId(typeId);
		projectRTypeDetailDao.addProjectRTimenode(projectRTimenode);
		String TypeGetNodeSQL="select p.id as typeId,p.project_type_name as typename,"
				+ "p.flag as pcalss,t.id as nodeid,t.timenode_name as nodename,"
				+ "t.timenode_index as nodeindex from project_type p left join "
				+ "project_type_timenode t on p.id=t.project_type_id where p.id in "
				+ "(select t.project_type_id from project_r_timenode t where project_id="+"'"+pId+"'"+")"
				+ "order by t.timenode_index";
		System.out.println(TypeGetNodeSQL);
		return projectRTypeDetailDao.querySql(TypeGetNodeSQL);
	}


	public String GetNodeAttachments(String pId, String pName) {
		String allAttahchmentSQL="select * from project_attachment where project_id ="+"'"+pId+"'"+" And DELETEFY='0'";
		System.out.println(allAttahchmentSQL);
		return projectRTypeDetailDao.querySql(allAttahchmentSQL);
	}


	public String GetNodeInfo(String pId, String pName) {
		String nodeInfoSQL="select p.id  as nodeid, p.timenode_name  as nodename,"
				+ "p.timenode_index as nodeindex,"
				+ "t.project_id as pid from project_r_timenode t "
				+ "left join project_type_timenode p "
				+ "on t.project_type_id =  p.project_type_id "
				+ "where t.project_id = "+"'"+pId+"'"
				+ "order by nodeindex";
		System.out.println(nodeInfoSQL);
		return projectRTypeDetailDao.querySql(nodeInfoSQL);
	}
}
